
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  event;

import java.util.Hashtable;


import logger.PoolLogger;


import pool.bean.Property_details_Bean;
import property.Codegenerator;
import property.Property;
import utility.ConvertToLower;
import utility.Input;
import utility.MessageGenerator;
import sms.SmsBuffer;
import User.Uservalidation;
import control.Control;
import control.RequestParameter;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class  Personcodegenerator implements Event
{
	String PERSONCODE="Personcode";
	String ITEM="Item";
	GetIdName gin;
	String type;
	String masterid;
	String MESSAGE;
	String  userid;
	String Request="";
	String Name;
	boolean flag;
	String TYPE="type";
	String MOBILENO="mobileno";
	String username;
	String userResponse ="Response : You have added \"TYPE\" And the Personcode for \"master\" is : " ;
	String Responce="Welcome to Open source Pool U Have Been successfully added as TYPE And U can give u r order through sms. Your personcode is : ";
	PoolLogger pl;
	
	public Personcodegenerator() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	public boolean getResult() 
	{	 
		return flag;
	}
	
	public void initializationData() 
	{	 
		gin = new GetIdName();
		PERSONCODE = gin.getId(PERSONCODE);
		MOBILENO = gin.getId(MOBILENO);
	}
	public void setObject(String Object)
	{		
	
		Name = gin.getItem(masterid);
		Property property = new Property();
		property.setMid(masterid);
		property.setPid(PERSONCODE);
		String value = property.getValue();
		if(value.equals("no$"))
		{	
			String newPersonCode;
			Codegenerator code = new Codegenerator(); 
			newPersonCode= code.RegisterItem(PERSONCODE);
			
			if(!newPersonCode.equals("Error"))
			{
				Hashtable<Object, Object>table= new Hashtable<Object, Object>();
				Responce = Responce.replace("TYPE","PEROSN");
				userResponse = userResponse.replace("TYPE","PEROSN");
				userResponse = userResponse.replace("master",Name);
				userResponse = userResponse+newPersonCode;
				Responce = Responce+newPersonCode;
				try 
				{
					Hashtable<Object, Object>hashtable1 = new Hashtable<Object, Object>();
					PERSONCODE=gin.getItem(PERSONCODE);
					hashtable1.put("pid", PERSONCODE);
					hashtable1.put("pv", newPersonCode);
					hashtable1.put("mid", Name);
					userid = "+911234567891";
					Uservalidation getpass = new Uservalidation();
					String password = getpass.getPasword(userid);
					Property_details_Bean propertydetailbean=new Property_details_Bean();
					propertydetailbean.setTable("property_details");
					RequestParameter req = new RequestParameter();
					req.setUsername(userid);
					req.setMessage("System Message");
					req.setPassword(password);
					req.setRequest("property_details");
					req.setProcess("add");
					propertydetailbean.initPool();
					propertydetailbean.setMid(Name);
					propertydetailbean.initPool();
					propertydetailbean.setReqParam(req);
					propertydetailbean.setPropertyHash(hashtable1);
					propertydetailbean.insert();
					flag=propertydetailbean.getResult();
					if(flag)
					{
						SmsBuffer smsBuffer  =new SmsBuffer();
						smsBuffer.addBufferLog(userid,userResponse);					
						property.setMid(masterid);
						property.setPid(MOBILENO);
						smsBuffer.addBufferLog(property.getValue(), Responce);
					}
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}	
		else
			flag =true;
	}
	public static void main(String[] args) 
	{
		
		Personcodegenerator personcode = new Personcodegenerator();
		personcode.initializationData();
		personcode.setObject("");
		personcode.getResult();	
	}
	
	public void SetData(String Product, String type, String masterid,String userid, String Process,String datetime,String request) 
	{	
				
		this.type = type;
		this.masterid = masterid;
		this.userid = userid;
		username = userid;
		
	}
	
	public boolean afterAdd() 
	{	
		return getResult();
	}
	
	public boolean afterDel() 
	{	
		return false;
	}
	
	public boolean afterMod() 
	{	
		return false;
	}
	
	public boolean afterView() 
	{	
		return false;
	} 
}
